<template>
	<!-- theme-bg1 -->
	<!-- theme-bg -->
	<view class="content " >
		<view class="" style="background: #93cff5; z-index: 9999; position: fixed;top: 0;width: 100%;">
			<search @searchChange="searchChange" class="theme-bg" ref="search"></search>
		</view>
		<!-- #ifndef H5  -->
		<view class="" style="height: 100rpx;background: #93cff5; ">

		</view>
		<!-- #endif -->
		<view class="" >
			<slideshow :swiperList="swiperList"></slideshow>
		</view>

		<view class="" style="position: relative;top: -20rpx;">
			<annunciate :informList="informList"></annunciate>
		</view>
		
	
		
		
		<!-- rightTitleIcon="↻" -->
		<view class="" style="margin: 0 20rpx;position: relative;top: -10rpx; overflow: hidden;">
			<view class="">
				<panel title="推荐创作者1" @more="moreAuthor" rightTitle="更多" rightTitleIcon=">"
					titleIcon="/static/icons/1.png">
					<authorList :authorList="framerList"></authorList>

				</panel>
			</view>
			
			<view class="" style="margin-top: 20rpx">
				<panel @more="to3" rightTitleIcon=">" title="测试" titleIcon="/static/icons/1.png">
					<view class="text-issue-box">
						<view :style="'background: url('+item.image+') no-repeat ;    background-size: 100% 100%;'"
							@tap="toList3(item,index)" class="item" v-for="(item,index) in testIssueList" :key="index">
							<view class="">
			
								{{item.title}}
							</view>
						</view>
					</view>
				</panel>
			</view>
			
			
		<!-- 	<view class="" style="margin-top: 30rpx;" >
				<panel @more="to2" rightTitleIcon=">" title="热门广告" titleIcon="/static/index/2.png">
					<ad style="width: auto; !important" :unit-id="'puj05ajghy88mbbv3m'"></ad>
				</panel>
			</view> -->
			
			<view class="" style="margin-top: 30rpx;">
				<panel title="推荐壁纸" rightTitle="true" titleIcon="/static/icons/1.png">
					<!-- <wallpaperList :wallpaperList="wallpaperList"></wallpaperList> -->
					<view class="" style="margin-top: 20rpx;">
						<worksList :currentImgs="imgsList" :itemStyle="{
							'width':'33.33%',
							'height':'350rpx',
						}"></worksList>
					</view>
					
					<view class="" style="text-align: center;"  >
						{{none}}
					</view>
				</panel>
				
				
			</view>



		</view>
		
		
		
		






		<modal ref="modal"></modal>

	</view>




</template>


<script>
	import search from "@/components/common/search.vue"
	import slideshow from "@/components/common/slideshow.vue"
	import annunciate from "@/components/common/annunciate.vue"
	import panel from "@/components/common/panel.vue"
	import authorList from "@/components/common/authorList.vue"
	import wallpaperList from "@/components/common/wallpaper-list.vue"
	import worksList from "@/components/common/works-list.vue"
	import {
		advertisingData11
	} from "@/mixin/advertisingData1.js"
	import {
		mixinAdvertising
	} from "@/mixin/advertising.js"
	export default {
		mixins: [advertisingData11, mixinAdvertising],
		components: {
			search,
			slideshow,
			annunciate,
			panel,
			authorList,
			wallpaperList,
			worksList
		},
		data() {
			return {
				none: "",
				pageIndex: 1,
				adShow: false,
				swiperList: [],
				informList: [],
				adUnitIdbanner: "",
				framerList: [],
				imgsList: [],
				testIssueList: [],
				params: {
					pageIndex: 1,
					pageSize: 10,
				},
				total: 0,
			}
		},
		onReachBottom() {
			this.adUnitIdbanner = this.advertisingData1(this.advertisingDataType.bannerList)
			if (this.total > this.params.pageIndex * this.params.pageSize) {
				this.params.pageIndex++;
				this.getImgsList();
			}else{
				console.log('asdfasdfasd')
				this.none = '没有数据了'
			}
		},
		onLoad() {
			this.getBanner()
			this.getInform()
			this.getFramer()
			this.getTestIssueList()
			this.getImgsList()
			setTimeout(() => {
				// this.initAd()
			}, 1000)

		},
		
		onShow() {
			
			// this.imgsList = []
			// this.pageIndex = 1
			// this.none = ''
			// this.getImgsList()

		},
		onShareAppMessage() {
			return {
				title: "精选壁纸头像免费拿，入驻丰厚奖励",
				path: "pages/index/index",
			};
		},
		methods: {
			to3() {
				var vipConfig = uni.getStorageSync('vipConfig')
				var user = uni.getStorageSync('user')
				if (!user && vipConfig.isSearchLogin) {
					this.$refs['modal'].modalName = 'Modal'
					return
				}
				uni.navigateTo({
					url: "/pages/test-lssue/list"
				})
			},
			hideModal() {
				this.$refs['modal'].modalName = ''
			},
			toList3(item, index) {
				var vipConfig = uni.getStorageSync('vipConfig')
				var user = uni.getStorageSync('user')
				if (!user && vipConfig.isSearchLogin) {
					this.$refs['modal'].modalName = 'Modal'
					return
				}
				// if (!this.isOpenGuanGao()) {
				uni.navigateTo({
					url: "/pages/test-lssue/details?title=" + item.title + '&_id=' + item.id
				})
				// }



			},
			// 获取测试答题列表
			async getTestIssueList() {
				var res = await this.$api.getData({
					dbName: "wx_test_issue",
					pageIndex: 1,
					pageSize: 100,
					whereJson: {
						hot: true
					}
				})
				this.testIssueList = res.rows
			},
			moreAuthor() {
				var vipConfig = uni.getStorageSync('vipConfig')
				var user = uni.getStorageSync('user')
				if (!user && vipConfig.isSearchLogin) {
					this.$refs['modal'].modalName = 'Modal'
					return
				}
				uni.switchTab({
					url: "/pages/author/author"
				})
			},
			// 上拉刷新重置列表
			reset(refresh) {
				this.none = ''
				this.params.pageIndex = 1
				if (refresh) {
					this.imgsList = []
				}
			},
			// 获取图片
			async getImgsList(refresh) {
				if (refresh) {
					this.reset()
				}
				var res = await this.$api.getData({
					dbName: "wx_imgs",
					sortRule: [{
						"name": "add_data",
						"type": "asc"
					}],
					whereJson: {
						img_type: 2,
						status: 1
					},
					pageIndex: this.params.pageIndex,
					pageSize: this.params.pageSize
				})
				if (refresh) {
					this.reset(true)
				}
				if (res.rows.length) {
					this.total = res.total
					this.imgsList.push(...res.rows)
				} else {
					this.none = '没有数据了'
				}

			},
			// 获取创作者
			async getFramer() {
				var res = await this.$api.getData({
					dbName: "wx_framer",
					pageIndex: 1,
					pageSize: 10,
				})

				this.framerList = res.rows

			},
			searchChange(val) {

			},
			getClipboardData() {
				var t = this;
				var vipConfig = uni.getStorageSync('vipConfig')
				if (vipConfig.shearCheckOpen != 1) {
					return
				}
				wx.getClipboardData({
					success: function(data) {
						if (data.data && !t.getURLFromString(data.data)) {
							var i = t.getURLFromString(data.data);
							wx.showModal({
								title: "检测到内容，是否粘贴？",
								content: i,
								confirmText: "确定",
								confirmColor: "#d4237a",
								success: function(a) {

									a.confirm ? t.$refs['search'].search = data.data : a.cancel
								}
							});
						}
					}
				})
			},
			getURLFromString: function(t) {
				var a = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
				return a.test(t) ? t.match(a)[0] : "";
			},
			// 初始化广告
			initAd() {
				var advertising = uni.getStorageSync('advertising')
				var adUnitId = this.advertisingData1(this.advertisingDataType.popUpList)
				console.log(adUnitId)
				// this.adUnitIdbanner = this.advertisingData1(this.advertisingDataType.bannerList)
				if (advertising.advertisingOpen == 1) {
					// 在页面中定义插屏广告
					let interstitialAd = null

					// 在页面onLoad回调事件中创建插屏广告实例
					if (uni.createInterstitialAd) {
						interstitialAd = uni.createInterstitialAd({
							adUnitId: adUnitId
						})
						interstitialAd.onLoad(() => {})
						interstitialAd.onError((err) => {})
						interstitialAd.onClose(() => {})
					}

					// 在适合的场景显示插屏广告
					if (interstitialAd) {
						interstitialAd.show().catch((err) => {
							console.error(err)
						})
					}
				}


			},


			// 获取通知
			async getInform() {
				var res = await this.$api.getData({
					dbName: "wx_inform",
					whereJson: {
						status: 1
					},
					pageIndex: 1,
					pageSize: 10,
				})
				this.informList = res.rows.filter(item => {
					return item.site == 3 || item.site == 1
				})
			},
			// 获取轮播图
			async getBanner() {
				var res = await this.$api.getData({
					dbName: "wx_banner",
					pageIndex: 1,
					pageSize: 10,
					whereJson: {
						status: 1
					},
					sortRule: [{
						name: 'sort',
						type: 'desc'
					}]
				})
				this.swiperList = res.rows.filter(item => {
					return item.site == 3 || item.site == 1
				})
			}
		}
	}
</script>
<style lang="scss" scoped>

</style>


<style>
	page {
		background: #93cff5;
	}

	.coup-introduce {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		/* font-size: 14px;
		color: #666;
		margin: 30rpx;
		white-space: normal;
		word-break: break-all;
		text-overflow: ellipsis;
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical; */
	}
</style>
<style scoped lang="scss">
	.text-issue-box {
		white-space: nowrap;
		margin-top: 20rpx;
		display: -webkit-box;
		align-items: center;
		overflow: auto;
		width: 100%;

		.item {

			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 28rpx;
			width: 270rpx;
			height: 180rpx;
			border-radius: 15rpx;
			margin-right: 20rpx;
			text-align: center;
			background: url(https://xinlianai.app1212.com/admin/upload/2020121314565611f8cb507c3bb3a8c684adcf259cfa24.jpg) no-repeat;
			background-size: 100% 100%;

			view {
				width: 210rpx;
				word-break: break-all;
				text-align: center;
				white-space: normal;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;

			}
		}
	}
</style>